<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class BaseController extends Controller
{
    //分页数
    protected $pagesize = 2;

    public function __construct()
    {
        $this->pagesize = config('app.pagesize', 2);
    }
    //图片上传
    public function upfile(Request $request){
        $pic='uploads/noimg.jpg';
        //上传节点名称
        $upNode=$request->get('node','article');
        if($request->hasFile('file')){
            $file=$request->file('file');
            $filename=$file->store($upNode,'upfile');
            $pic='/uploads/'.$filename;
        }
        return ['pic'=>$pic];
    }
    //删除图片
    public function delpic(Request $request){
        $path=$request->get('path');
        $filepath=public_path($path);
        if(file_exists($filepath)){
            unlink($filepath);
        }
        return ['code'=>200,'msg'=>'删除成功'];
    }
}
